home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 14 / Mac Magazin and MacEasy Magazine CD - Issue 14.iso / Wissenschaft & Technik / Tools Plus 2.6.1 Evaluation Kit / Tools Plus 2.6.1 / Tutorials / 5-Pop-Up Menus / Tutorial.c < prev    next >
C/C++ Source or Header  |  1995-08-01  |  4KB  |  136 lines

  1. //    Tools Plus Tutorial -- Pop-Up Menus
  2.  
  3.  
  4.  
  5.  
  6.  #include "ToolsPlus.h"
  7.  
  8.  
  9.  #define ordinaryPopUp    1                // Pop-up menu constants for more readable code…
  10.  #define popDownMenu        2
  11.  #define littlePopUp        3
  12.  
  13.  #define DoneButton            255
  14.  
  15.  
  16.  
  17.  TPPollRecord        Poll;                                // Polling record to retrieve event information
  18.  Boolean                ExitTheDemo;                // Should the demo terminate?
  19.  
  20.  short                    theButton;                    // Button number clicked in an alert
  21.  
  22.  
  23.  
  24.  void ApplicationInitialization (void);
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  //    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -
  32.  void main(void)
  33.  {
  34.     InitGraf(&qd.thePort);
  35.     InitFonts();
  36.     InitWindows();
  37.     InitMenus();
  38.     TEInit();
  39.     InitDialogs(0L);
  40.     MaxApplZone();
  41.  
  42.  
  43.     if (!InitToolsPlus(1, 1, UseColor))
  44.         ExitToShell();
  45.  
  46.     ApplicationInitialization();
  47.  
  48.     while (!ExitTheDemo)                    //Main Event Loop
  49.         {
  50.         if (PollSystem(&Poll))            //If an event is available, process the event…
  51.             {
  52.             switch (Poll.What)
  53.                 {
  54.  
  55.                 case doButton:    // User clicked a button ("Done" is the only button we have)…
  56.                     ExitTheDemo = true;
  57.                     break;
  58.  
  59.                 case doPopUpMenu: 
  60.                     switch (Poll.Menu.Num)
  61.                         {
  62.                         case ordinaryPopUp:
  63.                             // Put check mark (√) beside selected item. Previously selected
  64.                             // item is automatically deselected (this feature is optional).
  65.                             CheckPopUp(Poll.Menu.Num, Poll.Menu.Item, on);
  66.                             break;
  67.  
  68.                         case popDownMenu:
  69.                             // Your app would likely execute a process here…
  70.                             theButton = AlertBox(noteIcon, "\pYour application would do something now.", -OkAlert);
  71.                             break;
  72.  
  73.                         case littlePopUp:
  74.                             // Put bullet (•) beside selected item. Previously selected
  75.                             // item is automatically deselected (this feature is optional).
  76.                             PopUpMark(Poll.Menu.Num, Poll.Menu.Item, DotChar);
  77.                             break;
  78.                         }
  79.                     break;
  80.  
  81.                 default:
  82.                     break;                            //All other events are ignored
  83.                 }
  84.             }
  85.         }
  86.     }
  87.  
  88.  
  89.  //    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -    -
  90.  void ApplicationInitialization (void)
  91.     {
  92.     //    Do all the application setup before you start polling for events…
  93.  
  94.      #define        DemoWindow1        1
  95.  
  96.     WindowOpen(DemoWindow1, 0, 0, 225, 170, "\p", dBoxProc + wCenter, NoGoAway, Modal);
  97.  
  98.  
  99.     // Create a Pop-Up Menu that hides the "down arrow".  The pop-up menu is populated
  100.     // with icons.  Note that the Menu Manager adds 256 to the icon specifier (the
  101.     // number following the "^" mark). Example: ^44 +  256 = 300, or 'cicn' resource
  102.     // ID 300 is used.
  103.     NewPopUp(ordinaryPopUp, 100, 20, 206, 20, "\pSearch Here:", popupIconTitle + popupNoArrow, enabled);
  104.     PopUpMenu(ordinaryPopUp, 1, enabled, "\pDesktop^44");
  105.     PopUpMenu(ordinaryPopUp, 2, enabled, "\pHard Disk^45");
  106.     PopUpMenu(ordinaryPopUp, 3, enabled, "\pTools Plus^46");
  107.     PopUpMenu(ordinaryPopUp, 4, enabled, "\pTHINK C^47");
  108.     PopUpMenu(ordinaryPopUp, 5, enabled, "\pLibraries^47");
  109.     PopUpMenu(ordinaryPopUp, 6, enabled, "\p#Includes^47");
  110.     CheckPopUp(ordinaryPopUp, 1, on);    // Select first item by placing a check mark beside it
  111.  
  112.  
  113.     // Create a "pull-down" menu with a fixed title inside the control…
  114.     NewPopUp(popDownMenu, 100, 50, 206, 50, "\pFormat", popupFixedTitle, enabled);
  115.     PopUpMenu(popDownMenu, 1, enabled, "\pClear");
  116.     PopUpMenu(popDownMenu, 2, enabled, "\pParagraph…");
  117.     PopUpMenu(popDownMenu, 3, enabled, "\pCharacter…");
  118.     PopUpMenu(popDownMenu, 4, enabled, "\pStyle…");
  119.  
  120.  
  121.     // Create a pop-up menu using Geneva 9pt…
  122.     TextFont(geneva);
  123.     TextSize(9);
  124.     NewPopUp(littlePopUp, 100, 80, 133, 80, "\pSize:", popupUseWFont + popupNoArrow, enabled);
  125.     PopUpMenu(littlePopUp, 1, enabled, "\p9");
  126.     PopUpMenu(littlePopUp, 2, enabled, "\p10");
  127.     PopUpMenu(littlePopUp, 3, enabled, "\p12!•");    // This item is selected by being marked with a bulled (•)
  128.     PopUpMenu(littlePopUp, 4, enabled, "\p14");
  129.     PopUpMenu(littlePopUp, 5, enabled, "\p18");
  130.     PopUpMenu(littlePopUp, 6, enabled, "\p24");
  131.     PopUpMenu(littlePopUp, 7, enabled, "\p36");
  132.  
  133.  
  134.     NewButton(DoneButton, 85, 130, 140, 150, "\pDone", pushButProc + DefaultButton, enabled, notSelected);
  135.     ExitTheDemo = false;
  136.     }